CC=avr-gcc
MCU=atmega328p
#MCU=atmega1280
F_CPU=16000000UL
CFLAGS=-Wall -Os -DF_CPU=$(F_CPU) -mmcu=$(MCU) -Wl,-u,vfprintf -lprintf_min
OBJCOPY=avr-objcopy
BIN_FORMAT=ihex

PORT=/dev/ttyUSB0
BAUD=57600
PROTOCOL=stk500v1
PART=$(MCU)
AVRDUDE=avrdude -F -V
OBJS=	main.o io.o owire.o delay.o gpio.o clock.o\
	cmd.o adc.o extirq.o pwm.o arduino/pins_arduino.o\
	sensors/shtXX.o sensors/ds18x20.o

all: adas.hex

adas.hex: adas.elf
	$(OBJCOPY) -O $(BIN_FORMAT) -R .eeprom adas.elf adas.hex

adas.elf: $(OBJS)
	$(CC) $(CFLAGS) $(OBJS) -o adas.elf
	
.c.o:
	$(CC) -c $(CFLAGS) -o $@ $<

clean:
	rm -rf *.o *.elf *.hex sensors/*.o arduino/*.o

upload: adas.hex
	./reset.py $(PORT)
	$(AVRDUDE) -C avrdude.conf -c $(PROTOCOL) -p $(PART) -P $(PORT) -b $(BAUD) -U flash:w:$<

.PHONY: all clean upload
